home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / examples / exam12 / class1.d < prev    next >
Text File  |  1995-09-27  |  4KB  |  131 lines

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *    This source code is CONFIDENTIAL and
  8.  *    PROPRIETARY to Algorithms Corporation. Unauthorized
  9.  *    distribution, adaptation or use    may
  10.  *    be subject to civil and    criminal penalties.
  11.  *
  12.  *    Copyright (c) 1993 Algorithms Corporation
  13.  *    3020 Liberty Hills Drive
  14.  *    Franklin, TN  37064
  15.  *
  16.  *    ALL RIGHTS RESERVED.
  17.  *
  18.  *
  19.  *
  20.  */
  21.  
  22.  
  23.  /*  This example builds on the previous example by the addition of
  24.      two methods which allow users of this class to set and obtain the
  25.      value in the iName instance variable.  */
  26.  
  27. defclass  Class1  {
  28.     char    iName[30];
  29.     int    iCode;
  30.     iData;
  31. };
  32.  
  33. /*  Methods are declared in a similar fashion to C functions (using
  34.     ANSI prototypes) except as noted as follows.
  35.  
  36.    'imeth' is used to introduce instance methods with compile time argument
  37.     checking enabled.  Other method introductory commands are 'cmeth' which
  38.     introduces class methods with compile time argument chacking,  'ivmeth'
  39.     which introduces variable argument instance methods without compile time
  40.     checking,  and 'cvmeth' which defines variable argument class methods
  41.     without compile time argument checking.
  42.  
  43.     Since no return type is declared, Dynace defaults it to type 'object'.
  44.  
  45.     The name of the generic this method will be associated with is 'gSetName',
  46.     and since there is no explicit method name given, Dynace will just default
  47.     to 'm_gSetName'.  This is quite convinient since you rarely reference a
  48.     method directly.  If, however, a method is accessed directly (only
  49.     possible from within the same source file), a method name should be
  50.     explicitly declared for use.  The next example will show how to give a
  51.     method an explicit name.  
  52.  
  53.     Although no naming convention is enforced by Dynace, the suggested
  54.     convention is to use a leading 'g' followed by an uppercase letter to
  55.     designate a generic (instance or class) which is using compile-time
  56.     argument checking.  A leading 'v' followed by an uppercase letter is
  57.     used to indicate a variable argument generic, or one whos arguments are
  58.     not checked at compile time.  The 'g' stands for generic,  and the 'v'
  59.     stands for variable argument generic.
  60.  
  61.     A method may also be associated with a group of generics.
  62.  
  63.     The first argument to ALL methods is 'object self'.  Since it is always
  64.     the same,  Dynace defaults this declaration and the programmer need
  65.     not explicitly declare it.
  66.  
  67.     This specific generic (gSetName) takes an additional argument 'char *name'.
  68.  
  69.     Notice how the instance variables associated with the instance passed to
  70.     the method (as the first argument) are immediatly accessable.  This is
  71.     one reason for the instance variable nameing convension.  Otherwise,
  72.     it may be difficult to distinguish betweem instance variables and local
  73.     variables.
  74.  
  75.     This method simply copies the argument passed to the specified instance
  76.     variable.
  77.  
  78.     It is common practice, although not strictly required, under Dynace
  79.     to return an object from methods.  If no meaningful return value is
  80.     available, simply return the instance passed (self).
  81. */
  82.  
  83. imeth    gSetName(char *name)
  84. {
  85.     strcpy(iName, name);
  86.     return self;
  87. }
  88.  
  89. /*  This next method is defined as above except as follows:
  90.  
  91.     This new method, named get_name, is explictly defined to return a char *.
  92.     Also, the method is explicitly associated with the gGetName generic.
  93.     If you wanted to associated it with several generics you would use the
  94.     following syntax:
  95.  
  96.         imeth  char  * gGetName, gAnotherGeneric, gAbc : get_name ()
  97.  
  98.     This associates the method with all three generics.
  99.  
  100.     Since no arguments are declared, this method will only take the single,
  101.     default, argument of 'object self'.
  102.  
  103.     This method returns a pointer to the iName instance variable associated
  104.     with the instance passed.
  105. */
  106.  
  107. imeth    char    *gGetName : get_name ()
  108. {
  109.     return iName;
  110. }
  111.  
  112.  
  113. /*
  114.  *
  115.  *    This source code is CONFIDENTIAL and
  116.  *    PROPRIETARY to Algorithms Corporation. Unauthorized
  117.  *    distribution, adaptation or use    may
  118.  *    be subject to civil and    criminal penalties.
  119.  *
  120.  *    Copyright (c) 1993 Algorithms Corporation
  121.  *    3020 Liberty Hills Drive
  122.  *    Franklin, TN  37064
  123.  *
  124.  *    ALL RIGHTS RESERVED.
  125.  *
  126.  *
  127.  *
  128.  */
  129.  
  130.  
  131.